﻿using Core.AbstractEntities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Operations.Entities;
using Types;

namespace Test
{
    /// <summary>
    /// Testing AnalysisLexical
    /// </summary>
    [TestClass]
    public class UnitTest_AnalysisLexical
    {
        /// <summary>
        /// Verify if the element added is Numerical
        /// </summary>
        [TestMethod]
        public void Test_IsNumeric()
        {
            AnalysisLexical analisysLexical = new AnalysisLexical();
            HpElement hpElement = new HpElement();
            hpElement.Value = 3;
            Assert.AreEqual(true, analisysLexical.IsNumeric(hpElement));
            hpElement.Value = 3.5;
            Assert.AreEqual(true, analisysLexical.IsNumeric(hpElement));
            hpElement.Value = 0;
            Assert.AreEqual(true, analisysLexical.IsNumeric(hpElement));
            hpElement.Value = "3";
            Assert.AreEqual(false, analisysLexical.IsNumeric(hpElement));
        }
        /// <summary>
        /// Verify if the element added is a list
        /// </summary>
        [TestMethod]
        public void Test_IsList()
        {
            AnalysisLexical analisysLexical = new AnalysisLexical();
            HpElement hpElement = new HpElement();
            hpElement.Value = "{1 2 3}";
            Assert.AreEqual(true, analisysLexical.IsList(hpElement));
            hpElement.Value = 4;
            Assert.AreEqual(false, analisysLexical.IsList(hpElement));
        }
        /// <summary>
        /// Verify if the element added is a RPN program
        /// </summary>
        [TestMethod]
        public void Test_IsProgramRPN()
        {
            AnalysisLexical analisysLexical = new AnalysisLexical();
            Rpl testRPL = new Rpl();
            HpElement hpElement =new HpElement()
            {
                Value =  "« DUP IF 180 < THEN 180 + ELSE 180 - END »",
                Type= testRPL.GetType()
            };
            Assert.AreEqual(true, analisysLexical.IsRPL(hpElement));
            HpElement hpElement2 = new HpElement()
            {
                Value = (new Rpl() { Value = "« DUP IF 180 < THEN 180 + ELSE 180 - END " })
            };
            Assert.AreEqual(false, analisysLexical.IsRPL(hpElement2));
        }
        /// <summary>
        /// Verify if the element added implies a unitary operation
        /// </summary>
        [TestMethod]
        public void Test_IsCommandUnitary()
        {
            AnalysisLexical analisysLexical = new AnalysisLexical();
            HpElement hpElement = new HpElement();
            hpElement.Value = "DUP";
            Assert.AreEqual(true, analisysLexical.IsCommandUnitary(hpElement));
            hpElement.Value = "!";
            Assert.AreEqual(true, analisysLexical.IsCommandUnitary(hpElement));
            hpElement.Value = "^";
            Assert.AreEqual(false, analisysLexical.IsCommandUnitary(hpElement));
        }
        /// <summary>
        /// Verify if the element added implies a binary operation
        /// </summary>
        [TestMethod]
        public void Test_IsCommandBinary()
        {
            AnalysisLexical analisysLexical = new AnalysisLexical();
            HpElement hpElement = new HpElement();
            hpElement.Value = "+";
            Assert.AreEqual(true, analisysLexical.IsCommandBinary(hpElement));
            hpElement.Value = "*";
            Assert.AreEqual(true, analisysLexical.IsCommandBinary(hpElement));
            hpElement.Value = "DUP";
            Assert.AreEqual(false, analisysLexical.IsCommandBinary(hpElement));
        }

    }
}
